/**********************************************************************/
/*****                                                            *****/
/*****  TITLE:          BJPS Gender Paper (Djupe, McClurg, Sokhey)*****/                        
/*****  UPDATE:         December 2015                             *****/
/*****  DESC:           Code variables from the ISL to replicate  *****/
/*****                  (part of) McClurg's 2006 AJPS &           *****/
/*****                  Estimate models accounting for gender     *****/                        
/**********************************************************************/


/*Extended Description
*The analysis of the Indianapolis-St. Louis dataset (ICPSR 2962) utilizes
*files DS7 (Wave 2 main respondent-substantive) and DS13 (Wave 3 main respondent-substantive).
*This documentation file begins with those files, recodes key variables, and merges the files, which
*are then sufficient to reproduce our results.*/

cd "<local directory where mrw2.dta and mrw3.dta are found>"

/*Dependent Variable - Political Participation*/
*NOTE: The DV does not exist for Wave 4
foreach x in 2 3 {
use mrw`x'.dta	
recode po6 po7 po8 po9 (8 9=.a)
egen polpar=anycount(po6 po7 po8 po9), values(1)
save mrw`x'.dta, replace
}

/*Network Variables*/
/*Network Size*/
foreach x in 2 3 {
use mrw`x'.dta	
egen netsize=anycount(n1a n2a n3a n4a n5a),values(1 3 5 8 9)
save mrw`x'.dta, replace
}

/*Volume of political talk */
foreach x in 2 3 {
use mrw`x'.dta	
gen vpoltalk=0
	foreach y in 1 2 3 4 5 {
	recode n`y'j (8 9=.a)(-1 4=0)(3=1)(2=2)(1=3), gen(n`y'jr) //0=never (or missing)...3=often
	replace vpoltalk=vpoltalk+n`y'jr if n`y'jr<.
}
save mrw`x'.dta, replace
clear
}

/*% Agreeing discussants*/

use mrw2.dta
recode pp1b pp2b pp3b ep2b ep3b ep4b ep5b (-1=.a)
gen d1vote=pp1b if pp1b<.
replace d1vote=pp2b if pp2b<.
replace d1vote=pp3b if pp3b<.
gen d2vote=ep2b
gen d3vote=ep3b 
gen d4vote=ep4b 
gen d5vote=ep5b
save mrw2.dta, replace

use mrw3.dta
recode pp1b pp3b ep2b ep3b ep4b ep5b (-1=.a)
gen d1vote=pp1b if pp1b<.
replace d1vote=pp3b if pp3b<.
gen d2vote=ep2b
gen d3vote=ep3b 
gen d4vote=ep4b 
gen d5vote=ep5b
save mrw3.dta, replace


*Assesing Agreement for candidate preferences expressed (including "other"), first for each dyad and then averaged
foreach x in 2 3 {
use mrw`x'.dta
	foreach y in 1 2 3 4 5 {
	gen d`y'voteag=0 if d`y'vote<.
	replace d`y'voteag=1 if nuv2==d`y'vote & nuv2<4
}
gen dvoteag=0
replace dvoteag=dvoteag+d1voteag if d1voteag<.
replace dvoteag=dvoteag+d2voteag if d2voteag<.
replace dvoteag=dvoteag+d3voteag if d3voteag<.
replace dvoteag=dvoteag+d4voteag if d4voteag<.
replace dvoteag=dvoteag+d5voteag if d5voteag<.
gen dvoteagav=dvoteag/netsize
save mrw`x'.dta, replace
clear
}


/*Average political knowledge*/
foreach x in 2 3 {
use mrw`x'.dta	
gen npolknow=0
	foreach y in 1 2 3 4 5 {
	recode n`y'l (8 9=.a)(1=2)(3=1)(-1 5=0), gen(n`y'lr) // 0=not much (or missing), 1=avg amt, 2=great deal
	replace npolknow=npolknow+n`y'lr if n`y'lr<.
	}
gen apolknow=npolknow/netsize
save mrw`x'.dta, replace
}

/*Control Variables*/
/*Education*/
foreach x in 2 3 {
use mrw`x'.dta	
recode d11 (-1 98 99=.a)(0/11=0)(12=1)(13 14 15 20=2)(16=3)(17/19=4), gen(educ)
save mrw`x'.dta, replace
}

/*Household income*/
foreach x in 2 3 {
use mrw`x'.dta	
gen income=0 if d17==1 // ($14,999 or less)
replace income=1 if d17==5 // ($15,000 - $24,999)
replace income=2 if d18==5 // ($25,000 - $34,999)
replace income=3 if d19==5 // ($35,000 to 50,000)
replace income=4 if d20==5 // ($51,000 to 75,000)
replace income=5 if d20==1 // (> 75,000)
save mrw`x'.dta, replace
}

/*Age*/
foreach x in 2 3 {
use mrw`x'.dta	
recode d13 (9998 9999=.a), gen(yrborn)
gen age=1996-yrborn
save mrw`x'.dta, replace
}

/*Group memberships*/ 
foreach x in 2 3 {
use mrw`x'.dta	
egen groups=anycount(o2 o3 o5 o6 o7 o8 o9 o10), values(1)
save mrw`x'.dta, replace
}

/*Respondent knowledge*/
foreach x in 2 3 {
use mrw`x'.dta	
gen polknow=0
replace polknow=polknow+1 if kno1==5
replace polknow=polknow+1 if kno2==1
replace polknow=polknow+1 if kno3==1
save mrw`x'.dta, replace
}

/*Interest*/
foreach x in 2 3 {
use mrw`x'.dta
recode p1 (5=0)(3=1)(1=2)(8 9=.a), gen(interest)
save mrw`x'.dta, replace
}
/*Strength of partisanship*/
foreach x in 2 3 {
use mrw`x'.dta
gen pid7=0 if p4==1
replace pid7=1 if p4==5
replace pid7=2 if p5==5
replace pid7=3 if p5==7
replace pid7=4 if p5==1
replace pid7=5 if p3==5
replace pid7=6 if p3==1
recode pid7 (0 6=3)(1 5=2)(2 4=1)(3=0), gen(strpid)
save mrw`x'.dta, replace
}

/*Political contact*/
foreach x in 2 3 {
use mrw`x'.dta	
egen contact=anycount(po1 po3), values(1)
save mrw`x'.dta, replace
}

/*Female*/
foreach x in 2 3 {
use mrw`x'.dta
gen wave=`x'
recode d2 (8 9=.a)(1=0)(5=1), gen(female)
save mrw`x'.dta, replace
}

foreach x in 2 3 {
use mrw`x'.dta
keep caseid polpar vpoltalk apolknow dvoteagav educ income age group polknow interest strpid contact female netsize wave
save mrw`x'_cut.dta, replace
}

*Appending the two stripped down files
use mrw2_cut.dta
append using mrw3_cut.dta 
save mrs_cut.dta, replace

*These are the summary statistics reported in Table A.2 in the SI
sum polpar educ income age groups polknow interest strpid contact vpoltalk dvoteagav apolknow netsize female

*Table 1 - T-tests for network variables by gender
ttest netsize, by(female)
ttest vpoltalk, by(female)
ttest dvoteagav, by(female)
ttest apolknow, by(female)

*Table 3, Column 1 - "Replication of 1996 ISL Analysis"
nbreg polpar vpoltalk apolknow dvoteagav educ income age groups polknow interest strpid contact female

*Table 3, Column 2 - Modeling Gender
nbreg polpar c.vpoltalk##i.female c.apolknow##i.female c.dvoteagav##i.female educ income age groups polknow interest strpid contact

*Figure 2, Panel A
nbreg polpar vpoltalk apolknow dvoteagav educ income age groups polknow interest strpid contact if female==0
margins, dydx(vpoltalk apolknow dvoteagav) l(90)
estimates store Male
nbreg polpar vpoltalk apolknow dvoteagav educ income age groups polknow interest strpid contact if female==1
margins, dydx(vpoltalk apolknow dvoteagav) l(90)
estimates store Female

la var vpoltalk "Volume of Political Talk"
la var apolknow "Avg. Political Knowledge"
la var dvoteagav "% Agreeing Discussants"
coefplot Male, bylabel("Male Respondents") || Female, bylabel("Female Respondents") ///
		||,  xline(0, lc(gs10)) drop(_cons educ income age groups polknow interest strpid contact)  byop(graphregion(color(white))) mc(black) ciop(lp(dash) lc(black))

*Figure 2, Panel B
nbreg polpar c.vpoltalk##i.female c.apolknow##i.female c.dvoteagav##i.female educ income age groups polknow interest strpid contact
margins, dydx(female) at(apolknow=(0(.1)2)) atmeans level(90)
marginsplot, level(90) yline(0, lc(black)) ytitle("Marginal Effect of Gender (Female) on Participation") graphregion(color(white)) ///
	xtitle("Level of Network Knowledge") recastci(rspike) ciopt(lp(dash) lc(gs10)) plotop(mc(black) lc(black)) title("")

